package application;

import java.awt.Component;
import java.util.Map;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JList;

/**
 *
 * @author Alexis
 */
public class TankCouleurListRenderer extends DefaultListCellRenderer {

    private Map<CouleurTank, Icon> icons = null;

    public TankCouleurListRenderer(Map<CouleurTank, Icon> icons) {
        this.icons = icons;
    }

    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

        JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

        Icon icon = icons.get(value);

        label.setIcon(icon);
        label.setText(null);
        label.setHorizontalAlignment(JLabel.CENTER);
        return label;
    }
}